package org.jeecg.modules.system.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;
import org.jeecg.modules.system.entity.DbanFileNginx;
import org.jeecg.modules.system.service.IDbanNginxFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("/dban/file")
public class DbanFileNginxController {

    @Autowired
    private IDbanNginxFileService iDbanNginxFileService;

    /**
     * 分页查询附件信息
     */
    @GetMapping(value = "/queryPageList")
    public Result<?> queryPageList(DbanFileNginx dbanFileNginx,
                                   @RequestParam(name = "pageNo", defaultValue = "1") Integer pageNo,
                                   @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize,
                                   HttpServletRequest req) {
        QueryWrapper<DbanFileNginx> queryWrapper = QueryGenerator.initQueryWrapper(dbanFileNginx, req.getParameterMap());
        Page<DbanFileNginx> page = new Page<DbanFileNginx>(pageNo, pageSize);
        IPage<DbanFileNginx> pageList = iDbanNginxFileService.page(page, queryWrapper);
        return Result.ok(pageList);
    }


    /**
     * 根据id删除文件信息
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Result<DbanFileNginx> delete(@RequestParam(name = "id", required = true) String id) {

        Result<DbanFileNginx> result = new Result<DbanFileNginx>();
        DbanFileNginx dbanFileNginx = iDbanNginxFileService.getById(id);
        if (dbanFileNginx == null) {
            result.error500("未找到对应实体");
        } else {
            boolean ok = iDbanNginxFileService.removeById(id);
            if (ok) {
                result.success("删除成功!");
            }
        }
        return result;
    }

}
